import { messages } from "share/common";
import React, { Component, PropTypes } from 'react'
import {Button, Icon, Modal, Row, Col, Popover, Tabs} from 'antd'
import moment from 'moment'
import Condition from 'components/condition'
import UserFemale from 'images/user-female.png'
import UserMale from 'images/user-male.png'
import UserUnknow from "images/user-unknow.png";
import HonestView from "components/template/honest-view";
import ApplicantDetail from "./slide-document-applicant-detail"
import ResignationMark from './resignation-mark'
const If = Condition.If;
const TabPane = Tabs.TabPane;

class SlideDocumentApplicant extends Component {

  state = {
    modalVisible: false,
    modalType: 'honest',
  };

  userImg = {
    0: UserMale,
    1: UserFemale,
    2: UserUnknow
  };

  handleTabChange = key => this.setState({ modalType: key });

  renderModalContent = context => {
    const { modalType } = this.state;
    const { applicant, jobInfo, creditScore } = context;
    return creditScore.creditStatus === 1001 ?
      <ApplicantDetail applicant={applicant}/> :
      <Tabs activeKey={modalType} onChange={this.handleTabChange}>
        <TabPane tab={messages('common.baseInfo')/*基本信息*/} key='user' >
          <ApplicantDetail applicant={applicant}/>
        </TabPane>
        <TabPane tab={messages('common-1.key224')/*信用事件*/} key='honest' >
          <HonestView applicant={applicant} jobId={jobInfo.id}/>
        </TabPane>
      </Tabs>
  };

  showModal = (modalType, e) => {
    e.stopPropagation();
    this.setState({ modalVisible: true, modalType })
  };

  static contextTypes = {
    applicant: PropTypes.object,
    jobInfo: PropTypes.object,
    creditScore: PropTypes.object
  };

  render() {
    const { modalVisible } = this.state;
    const { applicant, jobInfo, creditScore } = this.context;
    return (
      <div
        className='slide-document-applicant'
        onClick={(e) => this.showModal('user', e)}
      >
        <img
          src={applicant.avatar || this.userImg[applicant.genderCode || 2]}
          className='slide-document-applicant-avatar'
        />
        <Row className='slide-document-applicant-base'>
          <Col style={{paddingRight: 20}}>
            {applicant.fullName}
            <span className="slide-document-applicant-base-employee-id">{applicant.employeeID}</span>
            <ResignationMark applicant={applicant}/>
          </Col>
        </Row>
        <Row className="slide-document-info" >
          <div className='slide-document-info-row'>
            {jobInfo.companyName || applicant.companyName}
            &nbsp;|&nbsp;
            {this.checkFunctionProfiles('department.full.path.disabled', [true]) ?
              (jobInfo.departmentName || applicant.departmentName) :
              (jobInfo.departmentPath || applicant.departmentPath)
            }
          </div>
        </Row>
        <If value={creditScore.creditStatus !== 1001}>
          <span
            className='slide-document-applicant-credit-score'
            onClick={(e) => this.showModal('honest', e)}
          >
            <If value={creditScore.rankFlag}>
              {messages('common-1.key368')/*信用等级*/}：{creditScore.creditRank}
              &nbsp;|&nbsp;
            </If>
            {messages('common-1.key367')/*信用分*/}：{creditScore.score}&nbsp;&nbsp;&nbsp;&nbsp;
          </span>
          <br/>
        </If>
        <a className="slide-document-info-more">
          {messages('common.detail')/*详情*/}
        </a>
        <Modal
          visible={modalVisible}
          title={messages('common-1.key570')/*员工信息*/}
          className='slide-document-applicant-modal'
          width={760}
          footer={[
            <Button type="primary" onClick={this.toState({ modalVisible: false })}>
              {messages('common-1.key41')/*关闭*/}
            </Button>
          ]}
          onCancel={this.toState({ modalVisible: false })}
        >
          {this.renderModalContent(this.context)}
        </Modal>
      </div>
    )
  }
}

export default SlideDocumentApplicant;
